﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using C1.Phone;


namespace ControlExplorer
{
    public class SampleViewModel
    {
        SampleSpec _spec;
        public SampleViewModel(SampleSpec spec)
        {
            _spec = spec;
            Title = spec.Title;
            Description = spec.Description;
            Thumbnail = new Uri("/ControlExplorer" + App.AssemblySuffix + ";component/Resources/SamplesPic/" + spec.Thumbnail + ".png", UriKind.Relative);
        }

        public string Title { get; set; }
        public string Description { get; set; }
        public Uri Thumbnail { get; set; }

        private UserControl _demo;
        public UserControl Demo 
        {
            get 
            {
                if (_demo == null) 
                {
                    _demo = _spec.CreateDemo();
                }
                return _demo;
            }
        }
    }

    public class SampleSpec
    {
        public string FullTypeName { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string Thumbnail { get; set; }

        internal UserControl CreateDemo()
        {
            var type = typeof(ViewModel).Assembly.GetType(FullTypeName);
            return Extensions.New<UserControl>(type);
        }
    }
}
